package com.example.comiccenter.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.comiccenter.domain.Comic;
import com.example.comiccenter.utils.ResultData;
import com.example.comiccenter.utils.SearchBean;
import com.example.comiccenter.service.ComicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping(value = "/comic",method = RequestMethod.POST)
public class ComicController {
    @Autowired
    private ComicService comicService;


    //分页查询
    @PostMapping("/getAllComic")
    public ResultData selectPage(@RequestBody SearchBean<Comic> searchBean){
        System.out.println("查询comic");
        return comicService.getAllComic(searchBean);
    }

    @PostMapping("/getMain")
    public ResultData getMain(){
        return comicService.getMain();
    }

    //添加comic
    @PostMapping("/addComic")
    public ResultData addComic(@RequestPart Comic comic, MultipartFile coverFile){
        System.out.println("插入comic："+comic);
        return comicService.addComic(comic,coverFile);
    }

    //删除comic
    @PostMapping("/deleteComic")
    public ResultData deleteComic(@RequestBody Comic comic){
        System.out.println("删除comic："+comic);
        return comicService.deleteComic(comic);
    }

    //更新comic
    @PostMapping("/updateComic")
    public ResultData updateComic(@RequestPart Comic comic, MultipartFile coverFile){
        System.out.println("修改comic："+comic);
        return comicService.updateComic(comic,coverFile);
    }


}
